package com.swtplayer;

import com.common.MyApp;
import com.swtplayer.AIDLService;

import android.annotation.SuppressLint;
import android.app.Service;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;

public class PlayerService extends Service {

	MyApp _app = MyApp.getInstance();
	private AIDLService.Stub mBinder = new AIDLService.Stub() {

		@Override
		public String GetAppPrecess() throws RemoteException {
			int processString = android.os.Process.myPid();
			return String.valueOf(processString);
		}

	};

	@Override
	public void onCreate() {
		_app.WLog("service create...");		 
		super.onCreate();
	}

	@Override
	public IBinder onBind(Intent intent) {
		_app.WLog("service onBind...");
		return mBinder;
	}

	@SuppressLint("NewApi")
	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		// TODO Auto-generated method stub
		Bundle bd = intent.getExtras();
		_app.WLog("service onStartCommand...");
		
		if (bd != null) {
			int pid = bd.getInt("pid");
			 String vid=bd.getString("vid") ;
			 String title=bd.getString("vid") ;
			 int position = bd.getInt("appdataindex");
			_app.WLog("service pid..."+pid);
			boolean restar = bd.getBoolean("restarplayer");
			if (restar == true) {
				android.os.Process.killProcess(pid);
				Intent i = new Intent();
				i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				i.setClass(PlayerService.this, InitActivity.class);
				i.putExtra("pid", android.os.Process.myPid());
				i.putExtra("restarplayer", true);
				i.putExtra("vid",vid);
				i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
				i.putExtra("title",title);
				i.putExtra("appdataindex",position);
				startActivity(i);
			}
		}
		
		return super.onStartCommand(intent, flags, startId);
		
	}

	
}
